<%@ page import="BusinessLogic.ControllerFacade" %>
<%@ page import="Presentation.WebUI.LinksGenerator" %>
<%@ page import="java.util.Collection" %>
<%@ page errorPage="error.jsp" %>

<%
	ControllerFacade c = (ControllerFacade)session.getAttribute("c");
    String sort = request.getParameter("sort");
    String movieNumber = request.getParameter("movieNumber");

    int amount = c.getListLength();
    int start = 0;
    String startParam = request.getParameter("start");
    if (startParam != null)
        start = Integer.parseInt(startParam);
%>

<h2><%=movieNumber%> <%=sort%> rated movies</h2>

<%
    Collection<String> list = c.getMostRatedMovies(Integer.parseInt(movieNumber), sort.equals("most"), start);

    int i = 0;
    String[] show = new String[list.size()];
    for(String m : list) {
        show[i] = LinksGenerator.movieLink(m);
        i++;
    }

    String last = "<br />No More Movies<br /><br />";
    out.println(LinksGenerator.showListWithNavButtons(show, request.getParameterMap(), start, amount, last));
%>
